package com.unicom.projt.fee;

import com.unicom.projt.http.AbstractHttpController;
import com.unicom.projt.http.UriConstants;
import com.unicom.projt.util.*;

/**
 * Created by IntelliJ IDEA.
 * User: Lee
 * Date: 11-12-31
 * Time: 下午9:44
 */
public class PaymentConfirmController extends AbstractHttpController<String> {
    private PaymentConfirmPage confirmPage;

    public PaymentConfirmController(PaymentConfirmPage confirmPage){
        super(String.class);
        this.confirmPage=confirmPage;
    }
    
    public void queryUnicomPayOrderState(String orderId){
        String svcCont = "<SvcCont><OrderId>" + orderId + "</OrderId></SvcCont>";
        String postXml = new PostXmlBuilder().setBiPCode("101").setTelNo(UserHolder.phoneNumber).setSvcCont(svcCont).createXml();
        this.sendRequest(UriConstants.URL, postXml);
    }
    
    @Override
    public void onNetworkAbort() {
        confirmPage.hideProgressDialog();
        ToastUtils.showMessage(confirmPage, "错误，网络连接被中断.");
    }

    @Override
    public void onNetworkError() {
        confirmPage.hideProgressDialog();
        ToastUtils.showMessage(confirmPage, "错误，网络连接错误.");
    }

    @Override
    public void onRequestFinish(String response) {
        confirmPage.hideProgressDialog();
        if (response == null || "".equals(response)) {
            confirmPage.hideProgressDialog();
            ToastUtils.showMessage(confirmPage, "错误，请稍候再试");
            return;
        }
        String respCode = SimpleXmlParser.getResponseCode(response);
        if(ResponseCode.SUCCESS.equals(respCode)){//订单成功
            confirmPage.showPaymentSuccessPage();//跳转到成功页面
        }else{
            ToastUtils.showMessage(confirmPage, SimpleXmlParser.getResponseDes(response));
        }
    }

    @Override
    public void onResponseError() {
        confirmPage.hideProgressDialog();
        ToastUtils.showMessage(confirmPage, "错误，返回结果错误.");
    }
}
